<?php

namespace App\Providers;

use App\Events\MasterAssureFund;
use App\Events\MasterOrderRefund;
use App\Events\OrderAppointed;
use App\Events\OrderDelivered;
use App\Events\OrderFinished;
use App\Events\OrderOffered;
use App\Events\SmsSent;
use App\Events\Tested;
use App\Listeners\MasterAssureFundListener;
use App\Listeners\MasterOrderRefundListener;
use App\Listeners\OrderAppointedListener;
use App\Listeners\OrderDeliveredListener;
use App\Listeners\OrderFinishedListener;
use App\Listeners\OrderOfferedListener;
use App\Listeners\SmsSentListener;
use App\Listeners\Subscribers\CacheEventSubscriber;
use App\Listeners\QueryExecutedListener;
use App\Listeners\Subscribers\OrderEventSubscriber;
use App\Listeners\TestedListener;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        /**
         * 测试用
         */
        Tested::class => [
            TestedListener::class,
        ],

        /**
         * 发出数据库请求
         */
        QueryExecuted::class => [
            QueryExecutedListener::class,
        ],

        /**
         * 发送短信
         */
        SmsSent::class => [
            SmsSentListener::class,
        ],

        /**
         * 师傅对订单报价
         */
        OrderOffered::class => [
            OrderOfferedListener::class,
        ],

        /**
         * 师傅已预约客户
         */
        OrderAppointed::class => [
            OrderAppointedListener::class,
        ],

        /**
         * 师傅已操作订单确认完成服务
         */
        OrderFinished::class => [
            OrderFinishedListener::class,
        ],

        /**
         * 师傅操作商家退款请求
         */
        MasterOrderRefund::class => [
            MasterOrderRefundListener::class,
        ],

        /**
         * 师傅缴纳质保金
         */
        MasterAssureFund::class => [
            MasterAssureFundListener::class,
        ],

        /**
         * 师傅已操作物流提货
         */
        OrderDelivered::class => [
            OrderDeliveredListener::class,
        ],

    ];

    /**
     * The subscriber classes to register.
     *
     * @var array
     */
    protected $subscribe = [
        CacheEventSubscriber::class,
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Event::listen('laravoole.requesting', function ($illuminate_request,$swoole_request = null) {
//            Log::info($illuminate_request->segments());
            if (is_a($swoole_request,'Swoole\Http\Request') && !empty($swoole_request->header['X-Forwarded-Proto'])){
                app('url')->forceScheme($swoole_request->header['X-Forwarded-Proto']);
            }
        });
        //
    }
}
